package cn.cxq.learning.circle_array_queue;

import java.util.Scanner;

public class Client {
    public static void main(String[] args) {

        boolean flag = true;
        Scanner scanner = new Scanner(System.in);
        CircleArrayQueue circleArrayQueue = new CircleArrayQueue(4);

        while (flag){
            System.out.println(
                    "---------------------数组模拟环形队列---------------------\n" +
                    "     a：插入数据                       g：取出数据\n" +
                    "     f：取出队列头                      s：遍历队列\n" +
                    "     c：队列存储数据个数                 e：退出\n" +
                    "-------------------------------------------------------\n" +
                    "请输入:"
            );

            switch (scanner.next().charAt(0)){
                case 'a':
                    System.out.println("请输入插入的数据：");
                    circleArrayQueue.add(scanner.nextInt());
                    break;
                case 'g':
                    try {
                        System.out.println("取出数据为：" + circleArrayQueue.get());
                    }catch (RuntimeException e){
                        System.out.println(e.getMessage());
                    }

                    break;
                case 'f':
                    try {
                        System.out.println("队列头为：" + circleArrayQueue.getFront());
                    }catch (RuntimeException e){
                        System.out.println(e.getMessage());
                    }
                    break;
                case 's':
                    System.out.println("遍历结果：");
                    circleArrayQueue.showQueue();
                    break;
                case 'c':
                    System.out.println("队列中数据个数为：" + circleArrayQueue.size() + "个");
                    break;
                case 'e':
                    System.out.println("再见~~~");
                    flag = false;
                    break;
                default:
                    break;
            }
        }
    }
}
